import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router.config'
import store from '../store/index'

// 解决重复点击路由报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  store.commit("changeTabActive", to.path)
  if (to.meta.title) {
    document.title = to.meta.title
  }else{
    document.title = to.query.title
  }
  next()
})

export default router
